<?php
class UserRecommendation extends Zend_Db_Table_Abstract {
	protected $_name = "user_recommendation";
	
	protected $_referenceMap = array (
	'FromUser' => array (
		'columns' => 'from_user', 
		'refTableClass' => 'User', 
		'refColumns' => 'id' 
	),
	'ToUser' => array (
		'columns' => 'to_user',
		'refTableClass' => 'User',
		'refColumns' => 'id'
	)
	);
	
	/**
	 * Find by unique constraint.
	 * 
	 * @param $fromUser
	 * @param $toUser
	 * @return user recommendation object
	 */
	public function findByUnique($fromUser, $toUser) {
		$where = $this->select()->where("from_user=?", $fromUser)->where("to_user=?", $toUser);
		return $this->fetchRow($where);
	}
	
	/**
	 * Add new entry.
	 * 
	 * @param $data
	 */
	public function addNew($data) {
		$obj = $this->findByUnique($data["from_user"], $data["to_user"]);
		if (!isset($obj)) {
			$this->insert($data);
		}
	}
}
?>